package com.chengyu.core.controller.actionLog;

import com.chengyu.core.controller.AdminBaseController;
import com.chengyu.core.domain.enums.ActionTypeEnums;
import com.chengyu.core.entity.CommonResult;
import com.chengyu.core.exception.ServiceException;
import com.chengyu.core.model.SysActionDataLog;
import com.chengyu.core.service.dataLog.ActionDataLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author LeGreen
 * @title 记录操作记录
 * @date 2021/1/8
 */
@Api(tags = "记录操作记录管理")
@Controller
@RequestMapping("/dataLog")
public class ActionDataLogController extends AdminBaseController {

    @Autowired
    private ActionDataLogService actionDataLogService;

    @ApiOperation(value = "保存")
    @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public CommonResult<String> add(SysActionDataLog sysActionDataLog) throws ServiceException {
        sysActionDataLog.setAppType(ActionTypeEnums.AppTypeTypes.SYS.getValue());
        sysActionDataLog.setAddBy(getSessionAdmin().getName());
        sysActionDataLog.setActionMemberId(getSessionAdmin().getId());
        actionDataLogService.add(sysActionDataLog);
        return CommonResult.success(null);
    }

    @ApiOperation(value = "获取")
    @ResponseBody
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public CommonResult<SysActionDataLog> get(SysActionDataLog sysActionDataLog) throws ServiceException {
        sysActionDataLog.setAppType(ActionTypeEnums.AppTypeTypes.SYS.getValue());
        SysActionDataLog sysActionDataLogResult = actionDataLogService.get(sysActionDataLog);
        return CommonResult.success(sysActionDataLogResult);
    }

}